package net.flyinggroup.mapstruct.extension;

import im.aop.loggers.advice.around.LogAround;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.convert.ConversionService;

@Slf4j
@SpringBootApplication
public class MapStructApplication {

    @Autowired
    private ConversionService service;

    public static void main(String[] args) {
        SpringApplication.run(MapStructApplication.class, args);
    }

    @EventListener(ApplicationReadyEvent.class)
    @LogAround
    public void learnExtension() {

        SeatConfiguration seatConfiguration = new SeatConfiguration();
        seatConfiguration.setSeatMaterial("water");
        seatConfiguration.setNumberOfSeats(10);

        SeatConfigurationDto seatConfigurationDto = SeatConfigurationMapper.INSTANCE.convert(seatConfiguration);
        assert seatConfigurationDto != null;
        log.info(seatConfigurationDto.toString());

        Car car = new Car();
        car.setId(1);
        car.setName("BMW");
        car.setSeatConfiguration(seatConfiguration);

        CarDTO dto = service.convert(car, CarDTO.class);
        assert dto != null;
        log.info(dto.toString());
    }
}
